﻿local L = LibStub( "AceLocale-3.0" ):GetLocale( "SimpleActionSets" )

local SAS_POS_DEFAULT = 270;
local SAS_OFFSET_DEFAULT = 0;
local SAS_OFFSET_TEMP;

function SimpleActionSets:Options_OnShow()
	self:Options_Update();
	SASOptionsMinimapShow:SetChecked( not self.db.profile.miniMapButton.hide );
	SASOptionsMinimapShowText:SetText( L["SAS_TEXT_OPTIONS_MINIMAP_SHOW"] );
	SASOptionsMinimapDrag:SetChecked( self.db.profile.miniMapButton.lock );
	SASOptionsMinimapDragText:SetText( L["SAS_TEXT_OPTIONS_MINIMAP_DRAG"] );
	SASOptionsMinimapPositionUndo:Disable();
	SASOptionsGeneralWarnings:SetChecked( not self.db.profile.noUIWarnings );
	SASOptionsGeneralWarningsText:SetText( L["SAS_TEXT_OPTIONS_GENERAL_WARNINGS"] );
	SASOptionsGeneralWarnings.tooltipText = L["SAS_TEXT_OPTIONS_GENERAL_WARNINGS_TOOLTIP"];
	SASOptionsGeneralEmptyBars:SetChecked( not self.db.profile.emptyBars );
	SASOptionsGeneralEmptyBarsText:SetText( L["SAS_TEXT_OPTIONS_GENERAL_EMPTYBARS"] );
	SASOptionsGeneralEmptyBars.tooltipText = L["SAS_TEXT_OPTIONS_GENERAL_EMPTYBARS_TOOLTIP"];
	SASOptionsGeneralEmptyButtons:SetChecked( self.db.profile.noEmptyButtons );
	SASOptionsGeneralEmptyButtonsText:SetText( L["SAS_TEXT_OPTIONS_GENERAL_EMPTYBUTTONS"] );
	SASOptionsGeneralEmptyButtons.tooltipText = L["SAS_TEXT_OPTIONS_GENERAL_EMPTYBUTTONS_TOOLTIP"];
	SASOptionsGeneralAutoRestore:SetChecked( self.db.profile.autoRestore );
	SASOptionsGeneralAutoRestoreText:SetText( L["SAS_TEXT_OPTIONS_GENERAL_AUTORESTORE"] );
	SASOptionsGeneralAutoRestore.tooltipText = L["SAS_TEXT_OPTIONS_GENERAL_AUTORESTORE_TOOLTIP"];
	SASOptionsGeneralAutoRestoreWarning:SetChecked( not self.db.profile.noAutoRestoreWarnings );
	SASOptionsGeneralAutoRestoreWarningText:SetText( L["SAS_TEXT_OPTIONS_GENERAL_AUTORESTOREWARN"] );
	SASOptionsGeneralAutoRestoreWarning.tooltipText = L["SAS_TEXT_OPTIONS_GENERAL_AUTORESTOREWARN_TOOLTIP"];
	self:SetMiniMapPositionTemp(self.db.profile.miniMapButton.position);
	SAS_OFFSET_TEMP = self.db.profile.miniMapButton.offset;
end

function SimpleActionSets:Options_General_Warnings( self )
	SimpleActionSets.db.profile.noUIWarnings = not self:GetChecked();
end

function SimpleActionSets:Options_General_EmptyBars(self)
	SimpleActionSets.db.profile.emptyBars = not self:GetChecked();
	SimpleActionSets:Actions_Display();
end

function SimpleActionSets:Options_General_EmptyButtons(self)
	SimpleActionSets.db.profile.noEmptyButtons = self:GetChecked();
	SimpleActionSets:Actions_Display();
end

function SimpleActionSets:Options_General_AutoRestore(self)
	SimpleActionSets.db.profile.autoRestore = self:GetChecked();
end

function SimpleActionSets:Options_General_AutoRestoreWarnings(self)
	SimpleActionSets.db.profile.noAutoRestoreWarnings = not self:GetChecked();
end

function SimpleActionSets:Options_Minimap_Show(self)
	SimpleActionSets.db.profile.miniMapButton.hide = not self:GetChecked();
	if ( self:GetChecked() ) then
		SASMinimapFrame:Show();
	else
		SASMinimapFrame:Hide();
	end
end

function SimpleActionSets:Options_Minimap_Drag(self)
	SimpleActionSets.db.profile.miniMapButton.lock = self:GetChecked();
end

function SimpleActionSets:Options_Minimap_Defaults()
	self.db.profile.miniMapButton.position = SAS_POS_DEFAULT;
	self.db.profile.miniMapButton.offset = SAS_OFFSET_DEFAULT;
	self:Minimap_PosUpdate();
end

function SimpleActionSets:Options_Minimap_Undo()
	self.db.profile.miniMapButton.position = self:GetMiniMapPositionTemp();
	self.db.profile.miniMapButton.offset = SAS_OFFSET_TEMP;
	self:Minimap_PosUpdate();
	self:Options_Update();
end

function SimpleActionSets:Options_Update()
	if ( self.db.profile.miniMapButton.position < 0 ) then self.db.profile.miniMapButton.position = self.db.profile.miniMapButton.position + 360; end
	SASButtonPos:SetValue(self.db.profile.miniMapButton.position);
	SASButtonOffset:SetValue(self.db.profile.miniMapButton.offset);
end